package com.kzx.blog.config.model;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @author kongz
 * @version 1.0 2021/11/23 10:41
 * @description 统一返回结果
 */
@Data
@AllArgsConstructor
public class ResultData<T> implements Serializable {
    private int code;//状态码
    private T data;//返回数据
    private String msg;//返回描述

    public ResultData(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResultData<T> ok(T data) {
        return new ResultData<>(200, data, "请求成功");
    }

    public static ResultData<Object> error(FailedException e) {
        return new ResultData<>(e.getErrorCode(), e.getErrorMsg());
    }
}
